﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _dataSet
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnTest_Click(object sender, EventArgs e)
        {
            string Sqlconn = System.Configuration.ConfigurationManager.ConnectionStrings["Conn"].ToString();

            using (SqlConnection conn = new SqlConnection(Sqlconn))
            {
                DataSet set = new DataSet();
                DataTable table = set.Tables.Add("T1");
                SqlDataAdapter sad = new SqlDataAdapter("select * from BaseUser", conn);
                sad.Fill(table);
                DataRow row = set.Tables[0].Rows[0];
            }

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            cbxTest.SelectedText = "请选择";
        }

        private void cbxTest_DropDown(object sender, EventArgs e)
        {
            List<Test> t = new List<Test> { 
                new Test(){ Id=1, Value="张三"},
                new Test(){ Id=2,Value="李四"}
            };

            cbxTest.DataSource = t;
            cbxTest.DisplayMember = "Value";
            cbxTest.ValueMember = "Id";

        }
    }

    public class Test
    {
        public int Id { get; set; }
        public string Value { get; set; }
    }
}
